<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>couchdb.client.ViewResults</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="couchdb-module.html">Package&nbsp;couchdb</a> ::
        <a href="couchdb.client-module.html">Module&nbsp;client</a> ::
        Class&nbsp;ViewResults
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class ViewResults</h1><p class="nomargin-top"></p>
<pre class="base-tree">
object --+
         |
        <strong class="uidshort">ViewResults</strong>
</pre>

<hr />
<p>Representation of a parameterized view (either permanent or temporary)
and the results it produces.</p>
<p>This class allows the specification of <tt class="rst-docutils literal"><span class="pre">key</span></tt>, <tt class="rst-docutils literal"><span class="pre">startkey</span></tt>, and
<tt class="rst-docutils literal"><span class="pre">endkey</span></tt> options using Python slice notation.</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>server = Server(<span class="py-string">'http://localhost:5984/'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>db = server.create(<span class="py-string">'python-tests'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>db[<span class="py-string">'johndoe'</span>] = dict(type=<span class="py-string">'Person'</span>, name=<span class="py-string">'John Doe'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>db[<span class="py-string">'maryjane'</span>] = dict(type=<span class="py-string">'Person'</span>, name=<span class="py-string">'Mary Jane'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>db[<span class="py-string">'gotham'</span>] = dict(type=<span class="py-string">'City'</span>, name=<span class="py-string">'Gotham City'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>map_fun = <span class="py-string">'''function(doc) {</span>
<span class="py-more">... </span><span class="py-string">    emit([doc.type, doc.name], doc.name);</span>
<span class="py-more">... </span><span class="py-string">}'''</span>
<span class="py-prompt">&gt;&gt;&gt; </span>results = db.query(map_fun)</pre>
<p>At this point, the view has not actually been accessed yet. It is accessed
as soon as it is iterated over, its length is requested, or one of its
<a href="couchdb.client.ViewResults-class.html#rows" class="link">rows</a>, <a href="couchdb.client.ViewResults-class.html#total_rows" class="link">total_rows</a>, or <a href="couchdb.client.ViewResults-class.html#offset" class="link">offset</a> properties are accessed:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>len(results)
<span class="py-output">3</span></pre>
<p>You can use slices to apply <tt class="rst-docutils literal"><span class="pre">startkey</span></tt> and/or <tt class="rst-docutils literal"><span class="pre">endkey</span></tt> options to the
view:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>people = results[[<span class="py-string">'Person'</span>]:[<span class="py-string">'Person'</span>,<span class="py-string">'ZZZZ'</span>]]
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">for</span> person <span class="py-keyword">in</span> people:
<span class="py-more">... </span>    <span class="py-keyword">print</span> person.value
<span class="py-output">John Doe</span>
<span class="py-output">Mary Jane</span>
<span class="py-output"></span><span class="py-prompt">&gt;&gt;&gt; </span>people.total_rows, people.offset
<span class="py-output">(3, 1)</span></pre>
<p>Use plain indexed notation (without a slice) to apply the <tt class="rst-docutils literal"><span class="pre">key</span></tt> option.
Note that as CouchDB makes no claim that keys are unique in a view, this
can still return multiple rows:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>list(results[[<span class="py-string">'City'</span>, <span class="py-string">'Gotham City'</span>]])
<span class="py-output">[&lt;Row id='gotham', key=['City', 'Gotham City'], value='Gotham City'&gt;]</span></pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">del</span> server[<span class="py-string">'python-tests'</span>]</pre>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Instance Methods</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.client.ViewResults-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">view</span>,
        <span class="summary-sig-arg">options</span>)</span><br />
      x.__init__(...) initializes x; see x.__class__.__doc__ for signature</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="couchdb.client.ViewResults-class.html#__repr__" class="summary-sig-name">__repr__</a>(<span class="summary-sig-arg">self</span>)</span><br />
      repr(x)</td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__getitem__"></a><span class="summary-sig-name">__getitem__</span>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">key</span>)</span></td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__iter__"></a><span class="summary-sig-name">__iter__</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="__len__"></a><span class="summary-sig-name">__len__</span>(<span class="summary-sig-arg">self</span>)</span></td>
          <td align="right" valign="top">
            
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__delattr__</code>,
      <code>__format__</code>,
      <code>__getattribute__</code>,
      <code>__hash__</code>,
      <code>__new__</code>,
      <code>__reduce__</code>,
      <code>__reduce_ex__</code>,
      <code>__setattr__</code>,
      <code>__sizeof__</code>,
      <code>__str__</code>,
      <code>__subclasshook__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== PROPERTIES ==================== -->
<a name="section-Properties"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Properties</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code class="link">list</code></span>
    </td><td class="summary">
        <a href="couchdb.client.ViewResults-class.html#rows" class="summary-name">rows</a><br />
      The list of rows returned by the view.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code class="link">int</code> or <tt class="rst-docutils literal"><span class="pre">NoneType</span></tt> for reduce views</span>
    </td><td class="summary">
        <a href="couchdb.client.ViewResults-class.html#total_rows" class="summary-name">total_rows</a><br />
      The total number of rows in this view.
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code class="link">int</code></span>
    </td><td class="summary">
        <a href="couchdb.client.ViewResults-class.html#offset" class="summary-name">offset</a><br />
      The offset of the results from the first row in the view.
    </td>
  </tr>
  <tr>
    <td colspan="2" class="summary">
    <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
      <code>__class__</code>
      </p>
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Method Details</span></td>
</tr>
</table>
<a name="__init__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">view</span>,
        <span class="sig-arg">options</span>)</span>
    <br /><em class="fname">(Constructor)</em>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  <dl class="fields">
    <dt>Overrides:
        object.__init__
        <dd><em class="note">(inherited documentation)</em></dd>
    </dt>
  </dl>
</td></tr></table>
</div>
<a name="__repr__"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">__repr__</span>(<span class="sig-arg">self</span>)</span>
    <br /><em class="fname">(Representation operator)</em>
  </h3>
  </td><td align="right" valign="top"
    >&nbsp;
    </td>
  </tr></table>
  
  repr(x)
  <dl class="fields">
    <dt>Overrides:
        object.__repr__
        <dd><em class="note">(inherited documentation)</em></dd>
    </dt>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== PROPERTY DETAILS ==================== -->
<a name="section-PropertyDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td align="left" colspan="2" class="table-header">
    <span class="table-header">Property Details</span></td>
</tr>
</table>
<a name="rows"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">rows</h3>
  The list of rows returned by the view.
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><i>unreachable</i>.rows(<span class="summary-sig-arg">self</span>)</span>
        - The list of rows returned by the view.
    </dd>
    <dt>Type:</dt>
      <dd><code class="link">list</code></dd>
  </dl>
</td></tr></table>
</div>
<a name="total_rows"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">total_rows</h3>
  <p>The total number of rows in this view.</p>
<p>This value is <code class="link">None</code> for reduce views.</p>
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><i>unreachable</i>.total_rows(<span class="summary-sig-arg">self</span>)</span>
        - The total number of rows in this view.
    </dd>
    <dt>Type:</dt>
      <dd><code class="link">int</code> or <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">NoneType</span></tt> for reduce views</dd>
  </dl>
</td></tr></table>
</div>
<a name="offset"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">offset</h3>
  <p>The offset of the results from the first row in the view.</p>
<p>This value is 0 for reduce views.</p>
  <dl class="fields">
    <dt>Get Method:</dt>
    <dd class="value"><span class="summary-sig"><i>unreachable</i>.offset(<span class="summary-sig-arg">self</span>)</span>
        - The offset of the results from the first row in the view.
    </dd>
    <dt>Type:</dt>
      <dd><code class="link">int</code></dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdb-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Dec 14 15:25:33 2009
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
